function importFile(otherStyles, otherScripts) {
  if (otherStyles === undefined) {
    otherStyles = [];
  }

  if (otherScripts === undefined) {
    otherScripts = [];
  }

  var pathName = window.document.location.pathname;
  var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);

  var setStyle = function (isBase) {
    var paths = [];
    for (var i = 0; i < otherStyles.length; i++) {
      var otherStyle = otherStyles[i];
      if (isBase) {
        if (otherStyle.indexOf('/') === 0) {
          paths.push(`<link rel="stylesheet" type="text/css" href="${projectName}${otherStyle}"/>`);
        }
      } else {
        if (otherStyle.indexOf('/') !== 0) {
          paths.push(`<link rel="stylesheet" type="text/css" href="${otherStyle}"/>`);
        }
      }
    }
    return paths.join("");
  }

  var setScript = function (isBase) {
    var paths = [];
    for (var i = 0; i < otherScripts.length; i++) {
      var otherScript = otherScripts[i];
      if (isBase) {
        if (otherScript.indexOf('/') === 0) {
          paths.push(`<script src="${projectName}${otherScript}"></script>`);
        }
      } else {
        if (otherScript.indexOf('/') !== 0) {
          paths.push(`<script src="${otherScript}"></script>`);
        }
      }
    }
    return paths.join("");
  };

  document.write( /*html*/ `
    <link rel="stylesheet" type="text/css" href="${projectName}/static/element-ui/theme-chalk/index.css" />
    <link rel="stylesheet" type="text/css" href="${projectName}/vueSystem/css/base.css" />
    ${setStyle(true)}
    ${setStyle(false)}
    <script src="${projectName}/vueSystem/js/definedFun.js"></script>
    <script src="https://upload.shinehao.com.cn/20180810145355jquery.min1.9.1.js"></script>
    <script src="https://upload.shinehao.com.cn/20180809103833lodash.js"></script>
    <script src="https://upload.shinehao.com.cn/20180809103828moment.js"></script>
    <script src="https://upload.shinehao.com.cn/20180912093557moment-zh-cn.js"></script>
    <script src="https://upload.shinehao.com.cn/20180809105917jqueryResize.js"></script>
    <script src="https://upload.shinehao.com.cn/20190514110446vue.min.v2.6.10.js"></script>
    <script src="https://upload.shinehao.com.cn/20191112090556element-ui2.11.1(revised).js"></script>
    <script src="${projectName}/vueSystem/js/base.js"></script>
    ${setScript(true)}
    <script src="${projectName}/vueSystem/js/request.js"></script>
    <script src="${projectName}/vueSystem/js/sysUtil.js"></script>
    ${setScript(false)}
  `);
}

function importFiles(files) {
  files = files || [];
  if (files.length === 0) {
    return;
  }

  var getFileElement = function(fileName){
    var array = fileName.split('.');
    if (array.length === 0) {
      return null;
    }
    var type = array[array.length - 1];
    if (type === 'js') {
      return `<script src="${fileName}"></script>`;
    }
    if (type === 'css') {
      return `<link rel="stylesheet" type="text/css" href="${fileName}">`;
    }
    return null;
  };

  var pathName = window.document.location.pathname;
  var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  var paths = [];
  for (var i = 0; i < files.length; i++) {
    var file = files[i];

    var fileName;
    if (file.indexOf('/') === 0) {
      fileName = projectName + file
    } else {
      fileName = file;
    }
    var htmlPath = getFileElement(fileName);
    if (htmlPath !== null) {
      paths.push(htmlPath);
    }
  }
  document.write(paths.join(""));
}

function importRichEditorFiles (otherFiles){
  importFiles([
    "https://upload.shinehao.com.cn/tinymce/langs/tinymce.min.js",
    "/static/tinymce-vue/tinymce-vue.min.js"
  ]);

  if (otherFiles !== undefined && otherFiles.length !== 0) {
    importFiles(otherFiles);
  }
}

function importTableColShowConfigFiles(){
  importFiles([
    "/vueSystem/components/css/tableColShowSelect.css",
    "/vueSystem/components/config/tableColConfig.js",
    "/vueSystem/components/tableColShowSelect.js",
    "/vueSystem/mixins/tableColShowMixin.js"
  ]);
}